import { NextRequest, NextResponse } from 'next/server'
import { match } from '@formatjs/intl-localematcher'
import Negotiator from 'negotiator'
export function middleware(request: NextRequest) {
  let headers = { 'accept-language': 'en-US,en;q=0.5' }
  let languages = new Negotiator({ headers }).languages()
  let locales = ['en-US', 'nl-NL', 'nl']
  let defaultLocale = 'en-US'

  match(languages, locales, defaultLocale)

  let cookie = request.cookies.get('nextjs')

  console.log(cookie)

  const allCookie = request.cookies.getAll()

  console.log(allCookie)

  console.log(request.cookies.has('nextjs'))
  console.log(request.cookies.delete('nextjs'))
  console.log(request.cookies.has('nextjs'))

  const response = NextResponse.next()
  response.cookies.set('vercel', 'fast')
  response.cookies.set({
    name: 'vercel',
    value: 'fast',
    path: '/'
  })
  cookie = response.cookies.get('vercel')
  console.log(cookie) // => { name: 'vercel', value: 'fast', Path: '/' }
  // The outgoing response will have a `Set-Cookie:vercel=fast;path=/` header.

  return response
}
